
using Godot;
using System;

public class BlockDataInfo : Control
{
    public enum StateEnum{
        normal,fluid
    }
    Panel panel;
    TextureRect sprite;
    Label label, fluid;
    public override void _Ready()
    {
        panel = GetNode<Panel>("Panel");
        sprite = GetNode<TextureRect>("Panel/Item");
        label = GetNode<Label>("Panel/Label");
        fluid = GetNode<Label>("Panel/fluid");
    }

    public void SetBlock(BlockData block)
    {
        if (block == null || block.Name == "air")
        {
            Visible = false;
            return;
        }
        else
        {
            Visible = true;
        }
        sprite.Texture = block.GetItemMaterial().texture;
        if (sprite.Texture == null) sprite.Texture = block.GetMaterial().texture;
        label.Text = block.GetMaterial().DisPlayName +$" {block.State},{block.power}";

        
        if(block.blockEntity!=null)
        {
            FluidData fd = block.blockEntity.GetFluid(0);
            if(fd!=null)
            {
                SetState(StateEnum.fluid);
                fluid.Text = $"{fd.name}:{fd.amount}/{fd.max}";
            }
        }else
        {
            SetState(StateEnum.normal);
        }
    }
    public void SetState(StateEnum state)
    {
        if (state == StateEnum.normal)
        {
            fluid.Visible = false;
            panel.SetSize(new Vector2(64, 24));
        }
        if (state == StateEnum.fluid)
        {
            fluid.Visible = true;
            panel.SetSize(new Vector2(64, 32));
        }
    }
}
